home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / asm / games / randomnumber / randomnumber020.s
Text File  |  1980-01-03  |  2KB  |  70 lines

  1. *******************************************************************************
  2. * GetRnd020()
  3. * -----------
  4. * $Inputs:    d0.l    = maximum random value to get..
  5. * $Outputs:    d0.l    = random value within the specified range..
  6. *
  7. * $Notes:    Random function re-written to take advantage of 020+ cpu`s &
  8. *        above.  Also 100% pc-relative.
  9. *
  10. * $SpeedTest:    Approx 50 random no.`s in 7 rasters on A1200/020 chipram
  11. *        Approx 50 random no.`s in 4 raster with fastram onboard!
  12. *******************************************************************************
  13. ciatodlow    =    $800
  14. ciatodhi    =    $A00
  15. ciatodmid    =    $900
  16. _ciaa        =    $BFE001
  17.  
  18.         section    chip,code_c
  19.  
  20. ee        cmp.b    #99,$dff006
  21.         bne.s    ee
  22.  
  23.         move.w    #$f0f,$dff180
  24.         move.w    #50-1,d7
  25. rands
  26.         moveq    #5,d0
  27.         bsr    GetRnd020
  28.  
  29.         dbra    d7,rands
  30.         move.w    #$bbc,$dff180
  31.         btst    #6,$bfe001
  32.         bne.s    ee
  33.         rts
  34.  
  35.         cnop    0,4
  36. GetRnd020:    lea    maxrand(pc),a0
  37.         move.l    d0,d2
  38.         beq.s    initrand
  39.         tst.b    seeded-maxrand(a0)
  40.         bne.b    valid_seed
  41.         bsr.s    initrand
  42.         move.l    d2,d0
  43. valid_seed:    move.l    d0,(a0)                ;maxrand
  44.         moveq    #0,d1
  45.         move.b    (_ciaa+ciatodlow).l,d1
  46.         add.l    random_seed(pc),d1
  47.         move.l    #$19660D,d0
  48.         mulu.l    d1,d1:d0
  49.         move.l    d0,random_seed-maxrand(a0)
  50.         clr.w    d0
  51.         swap    d0
  52.         move.l    (a0),d3                ;maxrand
  53.         mulu.w    d3,d0
  54.         clr.w    d0
  55.         swap    d0
  56.         rts
  57.         cnop    0,4
  58. initrand    st.b    seeded-maxrand(a0)
  59.         move.b    (_ciaa+ciatodhi).l,d0
  60.         lsl.l    #8,d0
  61.         move.b    (_ciaa+ciatodmid).l,d0
  62.         lsl.l    #8,d0
  63.         move.b    (_ciaa+ciatodlow).l,d0
  64.         move.l    d0,random_seed-maxrand(a0)
  65.         rts
  66.  
  67. maxrand        dc.l    0
  68. random_seed    dc.l    0
  69. seeded        dc.w    0
  70.